using System;

using Sunyi.Project.WebPoint.Common;
using Sunyi.Project.WebPoint.DataAccessController;

using Sunyi.Project.WebPoint.DataAccess;
using Sunyi.Project.WebPoint.DataContract;

namespace Sunyi.Project.WebPoint.DataAccessController
{
    public partial class UserDaoController : ProvisioningDaoController<User, UserDao>
    {
        public override void Insert(User user)
        {
            if (user.Id == Guid.Empty) user.Id = Guid.NewGuid();

            TransactionHelper.ProcessTransaction(() => { dao.Insert(user); dao.SaveRoles(user); });
        }

        public void Save(User user)
        {
            TransactionHelper.ProcessTransaction(() => { dao.Update(user); dao.SaveRoles(user); CacheProvider.Instance.Remove<User>(user.Id); });
        }

        protected override void FillEntity(User entity) { if (entity != null) { dao.FillRoles(entity); } }
    }
}
